import React from 'react';
import {Button, message, Modal,} from "antd";
import ProForm, {ProFormText} from "@ant-design/pro-form";
import { editReportStatus, editReject } from '@/services/report'

const AdoptOrReject = (props) => {

  //从props中把爱需要的数据结构出来
  const { visible, showModal, refs, id, RejectVisible, showRejectModal } = props

  //修改审核状态的方法
  const deepNote = async (status) => {
    console.log(status);
    const res = await editReportStatus(id,status)
    if (res.status === undefined) {
      message.success('修改成功');
      showModal(false);
      refs.current.reload();
    } else {
      message.error('修改失败');
    }
  }

  //举报驳回的事件 打开模态框 写入驳回理由
  const handleReject = async (data) => {
    data.status = 1
    console.log(data);
    const res = await editReject(id,data)
    console.log(res);
    if (res.status === undefined) {
      message.success('驳回成功');
      showRejectModal(false);
      refs.current.reload();
    } else {
      message.error('驳回失败');
    }
  }

  return (
    <div>
      <Modal
        title={'通过审核'}
        visible={visible}
        onCancel={() => showModal(false)}
        footer={false}
        destroyOnClose={true}
      >
        <ProForm
          submitter={{
            // 配置按钮的属性
            resetButtonProps: {
              style: {
                // 隐藏重置按钮
                display: 'none',
              },
            },
            submitButtonProps: {
              style:{
                //隐藏提交按钮
                display: 'none',
              }
            }
          }}
        >
          <ProForm.Item>
            <Button onClick={()=>deepNote(2)} type="primary" block>
              沉帖
            </Button>
          </ProForm.Item>
          <ProForm.Item>
            <Button onClick={()=>deepNote(3)} type="primary" danger block>
              删帖
            </Button>
          </ProForm.Item>
        </ProForm>
      </Modal>
      <Modal
        title="驳回理由"
        visible={RejectVisible}
        onCancel={() => showRejectModal(false)}
        footer={false}
        destroyOnClose={true}
      >
        <ProForm
          onFinish={(data) => handleReject(data)}
        >
          <ProFormText
            name="reject"
            label="驳回理由"
            placeholder="请输入驳回理由"
            rules={[
              {
                required: true,
                message: '请输入驳回理由!',
              },
            ]}
          />
        </ProForm>
      </Modal>
    </div>
  );
};

export default AdoptOrReject;
